package cn.itcast.entity;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * Question对象代表题库中的一道试题----questions.txt
 * 包含：题干、四个选项、正确答案
 */
public class Question implements java.io.Serializable {
    /**
     * 题干
     */
    private String title;
    /**
     * 若干选项
     */
    private List<String> options = new ArrayList<>();
    /**
     * 正确答案
     */
    private List<Integer> answer = new ArrayList<>();
    /**
     * 分数
     */
    private int score;
    /**
     * 难度等级
     */
    private int level;

    public static final long serialVersionUID = 9080302019871213L;

    public Question() {
    }


    public List<Integer> getAnswer() {
        return answer;
    }

    public List<String> getOptions() {
        return options;
    }


    public void setOptions(List<String> options) {
        this.options = options;
    }

    public String getTitle() {
        return title;
    }

    public void setAnswer(List<Integer> answer) {
        this.answer = answer;
    }


    public void setTitle(String title) {
        this.title = title;
    }

    public int getLevel() {
        return level;
    }

    public void setLevel(int level) {
        this.level = level;
    }

    public int getScore() {
        return score;
    }

    public void setScore(int score) {
        this.score = score;
    }


    public String toString() {
        StringBuilder sb = new StringBuilder(title + "\n");
        for (int i = 0; i < options.size(); i++) {
            sb.append((char) (i + 'A'))
                    .append(".")
                    .append(options.get(i))
                    .append("\n");
        }
//		sb.append("正确答案：");
//		for(int i=0;i<answer.size();i++){
//			sb.append((char)(answer.get(i)+'A')+",");
//		}
        sb.append("\n");
        return sb.toString();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Question question = (Question) o;

        if (score != question.score) return false;
        if (level != question.level) return false;
        if (!Objects.equals(title, question.title)) return false;
        if (!Objects.equals(options, question.options)) return false;
        return Objects.equals(answer, question.answer);
    }

    @Override
    public int hashCode() {
        int result = title != null ? title.hashCode() : 0;
        result = 31 * result + (options != null ? options.hashCode() : 0);
        result = 31 * result + (answer != null ? answer.hashCode() : 0);
        result = 31 * result + score;
        result = 31 * result + level;
        return result;
    }
}
